<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Working with XML namespaces</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="example.xmlwriter-simple.html">« Creating a simple XML document</a></li>
      <li style="float: right;"><a href="example.xmlwriter-oop.html">Working with the OO API »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="xmlwriter.examples.html">范例</a></li>
    <li>Working with XML namespaces</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="example.xmlwriter-namespace" class="section">
  <h2 class="title">Working with XML namespaces</h2>
  <p class="para">
   This example shows how to create namespaced XML elements.
  </p>
  <p class="para">
   <div class="example" id="example-5490">
    <p><strong>示例 #1 Working with XML namespaces</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$xw&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">xmlwriter_open_memory</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">xmlwriter_set_indent</span><span style="color: #007700">(</span><span style="color: #0000BB">$xw</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">xmlwriter_set_indent_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$xw</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'&nbsp;'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">xmlwriter_start_document</span><span style="color: #007700">(</span><span style="color: #0000BB">$xw</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'1.0'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'UTF-8'</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;A&nbsp;first&nbsp;element<br /></span><span style="color: #0000BB">xmlwriter_start_element_ns</span><span style="color: #007700">(</span><span style="color: #0000BB">$xw</span><span style="color: #007700">,</span><span style="color: #DD0000">'prefix'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'books'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'uri'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">xmlwriter_start_attribute</span><span style="color: #007700">(</span><span style="color: #0000BB">$xw</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'isbn'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">xmlwriter_start_attribute_ns</span><span style="color: #007700">(</span><span style="color: #0000BB">$xw</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'prefix'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'isbn'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'uri'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">xmlwriter_end_attribute</span><span style="color: #007700">(</span><span style="color: #0000BB">$xw</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">xmlwriter_end_attribute</span><span style="color: #007700">(</span><span style="color: #0000BB">$xw</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">xmlwriter_text</span><span style="color: #007700">(</span><span style="color: #0000BB">$xw</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'book1'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">xmlwriter_end_element</span><span style="color: #007700">(</span><span style="color: #0000BB">$xw</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">xmlwriter_end_document</span><span style="color: #007700">(</span><span style="color: #0000BB">$xw</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">xmlwriter_output_memory</span><span style="color: #007700">(</span><span style="color: #0000BB">$xw</span><span style="color: #007700">);</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;prefix:books isbn=&quot;&quot; prefix:isbn=&quot;&quot; xmlns:prefix=&quot;uri&quot;&gt;book1&lt;/prefix:books&gt;
</pre></div>
    </div>
   </div>
  </p>
 </div></div></div></body></html>